using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BlockOS.Client
{
    public class PausePanel : MonoBehaviour
    {
        private RectTransform m_rectTransform;
        public RectTransform rectTransform
        {
            get
            {
                if (m_rectTransform == null) m_rectTransform = GetComponent<RectTransform>();
                return m_rectTransform;
            }
        }

        private float m_FirstPosition;

        private void Start()
        {
            rectTransform.anchoredPosition = rectTransform.rect.width * Vector3.left;
            m_FirstPosition = rectTransform.anchoredPosition.x;
            StartCoroutine(AnimateShow(0.5f));
        }

        private IEnumerator AnimateShow(float time)
        {
            var timer = 0f;
            while (timer < time)
            {
                timer += Time.deltaTime;
                rectTransform.anchoredPosition = new Vector2(Mathf.SmoothStep(m_FirstPosition, 0, timer / time), rectTransform.anchoredPosition.y);
                yield return null;
            }
            rectTransform.anchoredPosition = Vector2.zero;
        }

        public IEnumerator AnimateHide(float time)
        {
            var timer = 0f;
            while (timer < time)
            {
                timer += Time.deltaTime;
                rectTransform.anchoredPosition = new Vector2(Mathf.SmoothStep(0, m_FirstPosition, timer / time), rectTransform.anchoredPosition.y);
                yield return null;
            }
            rectTransform.anchoredPosition = new Vector2(m_FirstPosition, rectTransform.anchoredPosition.y);
        }
    }
}
